#ifndef SOCKET_CAN_SOCKET_CAN_HPP
#define SOCKET_CAN_SOCKET_CAN_HPP

#include <cstdint>

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <net/if.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>

#include <linux/can.h>
#include <linux/can/raw.h>
#include <thread>
#include <functional>
#include <vector>
#include <string>
#include <memory>
#include <iostream>
namespace socket_can
{
class SocketCAN
{
public:
	SocketCAN(std::string ifname);

	SocketCAN(std::string ifname, long timeout);

	~SocketCAN();

	bool is_connected();

	void start_asyn_read();

	void register_asyn_read_cb(std::function<void(can_frame &frame)> fun);
	bool write_frame(can_frame &frame);

private:
	void asyn_read();
	void init();

	const std::string ifname_;

	int socket_;

	bool connected_;

	long timeout_;
	std::shared_ptr<std::thread> t_ptr_;

	std::vector<std::function<void(can_frame &frame)>> cb_fun_vector_;
};
} // namespace socket_can
#endif
//SOCKET_CAN_SOCKET_CAN_HPP
//std::function<void(void)> ff2 = std::bind(&Foo::f1, &foo);